//
//  BiPurchaseCheckViewController.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/4/27.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

static CGRect frame;

#import "BiPurchaseOrderCheckViewController.h"


#import "BiPurChaseCarInfoEntity.h"
#import "BiPurchaseStockEntity.h"
@interface BiPurchaseOrderCheckViewController ()<UITextViewDelegate>{

    __weak IBOutlet UIScrollView *_scrollview;
    
    __weak IBOutlet UITextView *_textfReason;
}

@property (weak, nonatomic) IBOutlet UILabel *labSupplyname;
@property (weak, nonatomic) IBOutlet UILabel *labBrand;
@property (weak, nonatomic) IBOutlet UILabel *labarcolor;
@property (weak, nonatomic) IBOutlet UILabel *labCarseries;
@property (weak, nonatomic) IBOutlet UILabel *labhouqsb;
@property (weak, nonatomic) IBOutlet UILabel *labhouqiao;
@property (weak, nonatomic) IBOutlet UILabel *labdriveroomtype;
@property (weak, nonatomic) IBOutlet UILabel *labdriveness;
@property (weak, nonatomic) IBOutlet UILabel *labdriveroomkind;
@property (weak, nonatomic) IBOutlet UILabel *labnotice;
@property (weak, nonatomic) IBOutlet UILabel *labzhouju;
@property (weak, nonatomic) IBOutlet UILabel *labbsxXhao;
@property (weak, nonatomic) IBOutlet UILabel *labfdjXhao;
@property (weak, nonatomic) IBOutlet UILabel *labCarPreforesale;

@property (weak, nonatomic) IBOutlet UILabel *labddsp;
@property (weak, nonatomic) IBOutlet UILabel *labztzgzc;
@property (weak, nonatomic) IBOutlet UILabel *labgzdsx;
@property (weak, nonatomic) IBOutlet UILabel *gzxxdfc;
@property (weak, nonatomic) IBOutlet UILabel *labcjpcdsx;
@property (weak, nonatomic) IBOutlet UILabel *labdpxxdfc;
@property (weak, nonatomic) IBOutlet UILabel *labdpsx;
@property (weak, nonatomic) IBOutlet UILabel *labgzsx;
@property (weak, nonatomic) IBOutlet UILabel *labztzzk;
@property (weak, nonatomic) IBOutlet UILabel *labzzkdfc;
@property (weak, nonatomic) IBOutlet UILabel *labztjxs;
@property (weak, nonatomic) IBOutlet UILabel *labxcck;
@property (weak, nonatomic) IBOutlet UILabel *labCarNumTotal;

@property (weak, nonatomic) IBOutlet UILabel *labPurchaser;
@property (weak, nonatomic) IBOutlet UILabel *labpurchaseNum;
@property (weak, nonatomic) IBOutlet UILabel *labCreattime;
@property (weak, nonatomic) IBOutlet UILabel *labApprover;

@property (weak, nonatomic) IBOutlet UILabel *labapproetime;


@end

@implementation BiPurchaseOrderCheckViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavBarTitle:@"订单审批"];
    
    [self setNavBarWithHidden:NO];
    
    [self setNavBackBtn];
    
    [self dataFill];
    [self setAutomaticallyAdjustsScrollViewInsets:YES];
    
    _scrollview.contentSize = CGSizeMake(MAIN_SCREEN_WIDTH,900);
    _textfReason.layer.borderColor = UIColorFromRGB(0xe5e5e).CGColor;
    _textfReason.layer.borderWidth = 1;
    _textfReason.layer.cornerRadius = 3;
    self.labCarNumTotal.textColor = UIColorFromRGB(ORANGE_COLOR_VALUE);
    
    if (isIPhone4) {
        _scrollview.contentSize = CGSizeMake(MAIN_SCREEN_WIDTH, 988);
    }

}


- (void)dataFill{
    
    BiPurChaseCarInfoEntity * carentity = self.centity.carEntity;
    
    BiPurchaseStockEntity * stockentity = self.centity.stockEntity;
    
    self.labSupplyname.text = self.centity.supplierName;
    self.labBrand.text = carentity.brand;
    self.labarcolor.text = carentity.carColor;
    self.labzhouju.text = carentity.wheelBase;
    self.labCarseries.text = carentity.carSeries;
    self.labdriveness.text = carentity.carDrive;
    self.labhouqiao.text = carentity.rearAxle;
    self.labnotice.text = carentity.announcementModel;
    self.labhouqsb.text = carentity.rearAxleRatio;
    self.labdriveroomtype.text = carentity.cabType;
    self.labdriveroomkind.text = carentity.cabModel;
    self.labbsxXhao.text = carentity.gearBoxModel;
    self.labfdjXhao.text = carentity.engineModel;
    
    if (stockentity) {
        self.labddsp.text = [NSString stringWithFormat:@"%d",(int)stockentity.orderApproval];
        self.labztzgzc.text = [NSString stringWithFormat:@"%d",(int)stockentity.refitting];
        self.labgzdsx.text = [NSString stringWithFormat:@"%d",(int)stockentity.refitStayOnline];
        self.gzxxdfc.text = [NSString stringWithFormat:@"%d",(int)stockentity.refitOffline];
        self.labcjpcdsx.text = [NSString stringWithFormat:@"%d",(int)stockentity.paichanStayOnline];
        self.labdpxxdfc.text = [NSString stringWithFormat:@"%d",(int)stockentity.chassisOffline];
        self.labdpsx.text = [NSString stringWithFormat:@"%d",(int)stockentity.chassisOnline];
        self.labgzsx.text = [NSString stringWithFormat:@"%d",(int)stockentity.refitOnelie];
        self.labztzzk.text = [NSString stringWithFormat:@"%d",(int)stockentity.zhongzhuanStorehouse];
        self.labzzkdfc.text = [NSString stringWithFormat:@"%d",(int)stockentity.zhongzhuanStorehouseStay];
        self.labztjxs.text =[NSString stringWithFormat:@"%d",(int)stockentity.dealerNum];
        self.labxcck.text = [NSString stringWithFormat:@"%d",(int)stockentity.nowStorehouse];
        self.labCarNumTotal.text = [NSString stringWithFormat:@"库存合计:%d",(int)stockentity.storehouseTotal];
    }

    self.labpurchaseNum.text = self.centity.purchaseCount;
    self.labPurchaser.text = self.centity.userName;
    
    self.labapproetime.text = self.centity.ratifyTime;
    self.labCreattime.text = self.centity.createTime;
    
    _textfReason.text = self.centity.rejectReason;
    
    self.labApprover.text = [BiUserEntity sharedInstance].name;
    self.labapproetime.text = [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"];
}


#pragma mark -textview delegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
    
    if ([@"\n" isEqualToString:text] == YES)
    {
        [textView resignFirstResponder];
        
        
        return NO;
    }
    return YES;
}

- (void)textViewDidBeginEditing:(UITextView *)textView{
    frame= _scrollview.frame;
    
    if (isIPhone4) {
            _scrollview.frame = CGRectMake(0, _scrollview.frame.origin.y - 176, _scrollview.frame.size.width, _scrollview.frame.size.height);
    }else{
    
            _scrollview.frame = CGRectMake(0, _scrollview.frame.origin.y - 216, _scrollview.frame.size.width, _scrollview.frame.size.height);
    }
    

    
}


- (void)textViewDidEndEditing:(UITextView *)textView{
    
    [textView resignFirstResponder];

    _scrollview.frame = frame;
    
}


- (IBAction)btnCheckClick:(UIButton *)sender {
    NSString * stutas = nil;
    if (1 == sender.tag) {
        //批准
        stutas = @"1";
    }else if (2 == sender.tag){
        //驳回
        stutas = @"0";
    }
    
    NSDictionary * paraDic = [NSDictionary dictionaryWithObjectsAndKeys:self.centity.e_id,@"id",
                              [BiUserEntity sharedInstance].userid,@"approvedId",
                              [BiUtil stringFromFomate:[NSDate date] formate:@"yyyy-MM-dd hh:mm"],@"approvedTime",
                              _textfReason.text,@"returnBack",
                              stutas,@"status",nil];
    
    [[BiNetEngine shareInstance] requestPurchaseOrderCheck:self paraDict:paraDic];
    
    [self asyshowHUDView:WAITING CurrentView:self];
    
}


#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    [self removeHUDView:self];
    
    NSDictionary * entity_ = (NSDictionary *)entity;
    
  //  [self showMessage:entity_[@"result_info"]];
    
    if ([entity_[@"response_status"] integerValue] != 200) {
        
        return;
        
    }
    
    switch (tag) {
        case NET_GET_PURCHASE_ORDER_CHECK:
        {
            [self.navigationController popViewControllerAnimated:YES];
            
        }
            break;
            
        default:
            break;
    }
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
    
}


@end
